<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <!--360浏览器优先以webkit内核解析-->

    <title>H+ 后台主题UI框架 - 主页示例</title>

    <link rel="shortcut icon" href="favicon.ico"/>
    <link rel="stylesheet" href="static/js/plugins/layui/css/layui.css">
    <link href="static/css/font-awesome.css?v=4.4.0" rel="stylesheet"/>
    <link href="static/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="static/css/animate.css" rel="stylesheet"/>
    <link href="static/css/style.css?v=4.1.0" rel="stylesheet"/>
    <style>
        #demo1 {
            width: 100px;
            height: 100px;
        }

        .ibox-title {
            min-height: 15px;
        }

        .ml_20 {
            margin-left: 20px;
        }

        .w100 {
            width: 100px !important;
        }

        .mt-60 {
            margin-top: -60px;
        }

        .layui-table-cell {

            text-align: center;

            height: auto;

            white-space: normal;

        }

        .layui-table img {
            max-width: 300px
        }

        .tishi {
            color: red;
        }

        .tishi1 {
            color: red;
        }

        .tishi2 {
            color: red;
        }

        .tishi3 {
            color: red;
        }

        .tishi0 {
            color: red;
        }
    </style>
</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="demoTable">
                    搜索：
                    <div class="layui-inline">
                        <input class="layui-input" name="id" id="demoReload" autocomplete="off">
                    </div>
                    <select style="height: 38px; border: darkgrey" class="ipt" id="roleId" name="city" lay-verify="">
                        <option value="全查询">全查询</option>
                        <option value="仅查询用户名">仅查询用户名</option>
                        <option value="仅查询手机号">仅查询手机号</option>
                        <option value="仅查询性别">仅查询性别</option>
                        <option value="仅查询邮箱">仅查询邮箱</option>
                        <option value="通过状态查询">通过状态查询</option>
                    </select>
                    <button class="layui-btn" data-type="reload" id="ss">查询</button>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="wrapper wrapper-content animated fadeInRight mt-60">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <table class="layui-hide" id="test" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="static/js/jquery.min.js?v=2.1.4"></script>
<script src="static/js/bootstrap.min.js?v=3.3.7"></script>
<script src="static/js/plugins/layer/layer.min.js"></script>
<script src="static/js/plugins/layui/layui.js"></script>

<!-- 自定义js -->
<script src="static/js/content.js"></script>
<!-- Peity -->
<script src="static/js/demo/bootstrap-table-demo.js"></script>

<!-- 欢迎信息 -->
<script src="static/js/welcome.js"></script>

<%--	<script type="text/html" id="checkboxTpl">--%>
<%--		<!-- 这里的 checked 的状态只是演示 -->--%>
<%--	<input type="checkbox" name="lock" value="{{d.id}}" title="锁定" lay-filter="lockDemo" {{ d.id==10006 ? 'checked' : ''--%>
<%--		}}>--%>
<%--	</script>--%>
<%--	<script type="text/html" id="barTb">--%>
<%--		<a class="layui-btn layui-btn-warm" lay-event="add">添加</a>--%>
<%--		<a class="layui-btn layui-btn-danger" lay-event="delete">批量删除</a>--%>
<%--	</script>--%>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delAll"> 批量删除</button>
    </div>
</script>
>
<%--	<script type="text/html" id="checkboxTpl">--%>
<%--		<!-- 这里的 checked 的状态只是演示 -->--%>
<%--		<input type="checkbox" name="lock" value="{{d.id}}" title="锁定" lay-filter="lockDemo" {{ d.id == 10006 ? 'checked' : '' }}>--%>
<%--	</script>--%>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">修改价格</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">取消订单</a>
</script>
<script>
    layui.use(['form', 'upload', 'table', 'element', 'layer', 'laydate'], function () {
        let $ = layui.jquery
        let upload = layui.upload
        let element = layui.element
        let layer = layui.layer;
        let laydate = layui.laydate;
        let table = layui.table;
        var form = layui.form
        laydate.render({
            elem: '#grounding_date'
            //设置开始日期、日期日期的 input 选择器
            //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
            , range: ['#grounding_date_from', '#grounding_date_to']
        });
        $("input[name=name]").blur(function () {
            let name = $("input[name=name]").val();
            if (name.length > 8) {
                $(".tishi").text("用户名不得超过8个字符").show(200);
                $(".tishi").delay(2500).hide(200);
            }
        });
        $("input[name=email]").blur(function () {
            let name = $("input[name=email]").val();
            var ePattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            if (ePattern.test(name) != true && (name != null && name != "")) {
                $(".tishi2").text("邮箱格式输入错误").show(200);
                $(".tishi2").delay(2500).hide(200);
            }
            $.ajax({
                "url": "member?opr=checkNameemail",
                "dataType": 'json',
                "type": 'post',
                "data": {name: name},
                "success": function (date) {
                    if (date == true) {
                        // 对date页面进行操作
                        $(".tishi2").text("邮箱已存在 请更换").show(200);
                        $(".tishi2").delay(2500).hide(200);
                    }
                },
                "error": function () {

                }
            });
        })
        $("input[name=phone]").blur(function () {
            let name = $("input[name=phone]").val();
            var mPattern = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[05-9]))\d{8}$/;
            if (mPattern.test(name) != true && (name != null && name != "")) {
                $(".tishi3").text("手机号格式输入错误").show(200);
                $(".tishi3").delay(2500).hide(200);
            }
        });
        //上传文件
        var uploadInst = upload.render({
            elem: '#test1'
            , url: 'member?opr=upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
                element.progress('demo', '0%'); //进度条复位
                layer.msg('上传中', {icon: 16, time: 0});
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                // 给隐藏表单赋值
                $("#photo").val(res.imgSrc);
                $('#demoText').html('');
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
            //进度条
            , progress: function (n, elem, e) {
                element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                if (n == 100) {
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });
//初始化时查询
        let tableIns = table.render({
            elem: '#test',
            height: 480,
            url: 'spcx?opr=dingdancx',
            page: true,
            skin: 'line',
            toolbar: '#toolbarDemo',
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', title: '编号', sort: true},
                {field: 'dingdanbh', title: '订单编号', sort: true},
                {field: 'add_time', title: '下单时间', sort: true},
                {field: 'name', title: '用户名', sort: true},
                {field: 'img', title: '商品图片', templet: function (d) {
                        return '<img onclick="showimg(this)" id="driimg" style="display: inline-block; width: 50px; height: 50px; border-radius:50%;" src="' + d.img + '">';
                    }
                },
                {field: 'spname', title: '商品名称', sort: true},
                {
                    field: 'zt', title: '订单状态', align: 'center', sort: true, templet: function (d) {
                        var e = d.zt;
                        if (e == 0) {
                            e = '<a style="color: #ed2a4a" lay-event="jin">待付款 </a>';
                            return e;
                        } else if (e == 1) {
                            e = '<a style="color: #ff6f00" lay-event="jin">待发货</a>';
                            return e;
                        } else if (-1 == e) {
                            e = '<a style="color: #36ee5e" lay-event="jin">待收获</a>';
                            return e;
                        }
                    }
                },
                {field: 'shouhou', title: '售后', align: 'center', sort: true, templet: function (c) {
                        var a = c.shouhou;
                        if (a == 0) {
                            a = '<a style="color: #ed2a4a" lay-event="jin">待买家收货</a>';
                            return a;
                        } else if (a == 1) {
                            a = '<a style="color: #00a6ff" lay-event="jin">待商家处理</a>';
                            return a;
                        }
                    }},
                {field: 'shuliang', title: '数量', sort: true},
                {field: 'jg', title: '价格', sort: true},
                {field: 'shoukuan', title: '实收款', sort: true},
                {title: '操作', width: "12%", toolbar: '#barDemo'}]]
        })
        table.on('toolbar(test)', function (obj) {
            switch (obj.event) {  // 监听添加操作
                case 'add':// 监听添加操作
                    let index = layer.open({
                        title: '添加用户',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['100%', '100%'],
                        content: 'add.jsp',
                        end: function () {
                            location.reload();
                        }
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                    break;
                case 'delAll':
                    var checkStatus = table.checkStatus('test'),
                        data = checkStatus.data,
                        userId = "";
                    if (data.length > 0) {
                        for (var i in data) {
                            userId += data[i].id + ",";
                        }
                        console.log(userId);//打印获取到选中的id，用，分割
                        layer.confirm('确定删除选中的用户？', {icon: 3, title: '提示信息'}, function (index) {
                            $.ajax({
                                url: "member?opr=del",
                                type: "POST",
                                data: {id: userId},
                                success: function (msg) {
                                    if (msg == "true") {
                                        layer.msg('删除成功!', {icon: 1, time: 100});
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="用户操作";
                                        let gn="用户批量删除";
                                        let jg="成功";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                        tableIns.reload({
                                            page: {
                                                curr: 1
                                            }
                                        });
                                    } else {
                                        layer.msg('删除失败', {time: 100});
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="用户操作";
                                        let gn="用户批量删除";
                                        let jg="失败";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                    }
                                }
                            });
                        });
                    } else {
                        layer.msg('请选择删除的数据!', {icon: 1, time: 1000});  //如果未选择数据，则提示。
                    }
                    break;
            }
        });
        //条件查询
        $("#ss").click(function () {
            var p_name = $(".layui-input").val()
            var myselect = document.getElementById("roleId");
            var index = myselect.selectedIndex;// selectedIndex是所选中的项的index
            myselect.options[index].value;
            let rr = myselect.options[index].text;
            if (p_name == null || p_name == "") {
                tableIns.reload({
                    url: 'member?opr=getAll',
                    page: {
                        curr: 1
                    }
                })
            } else if (rr == '通过状态查询' && p_name !== null || p_name !== "") {
                if (p_name == "禁用" || p_name == "启用") {
                    tableIns.reload({
                        url: 'member?opr=ztcx',
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                } else if (rr == '全查询' && p_name !== null && p_name !== "") {
                    tableIns.reload({
                        url: 'member?opr=getAll2',
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                } else if (rr == '仅查询用户名' && p_name !== null || p_name !== "") {
                    tableIns.reload({
                        url: 'member?opr=yhmcx&rr=' + rr,
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                } else if (rr == '仅查询手机号' && p_name !== null || p_name !== "") {
                    tableIns.reload({
                        url: 'member?opr=yhmcx&rr=' + rr,
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                } else if (rr == '仅查询性别' && p_name !== null || p_name !== "") {
                    tableIns.reload({
                        url: 'member?opr=yhmcx&rr=' + rr,
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                } else if (rr == '仅查询邮箱' && p_name !== null || p_name !== "") {
                    tableIns.reload({
                        url: 'member?opr=yhmcx&rr=' + rr,
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                }
            }
        })

        table.on('tool(test)', function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case'del':
                    layer.confirm('真的删除吗', function (index) {
                        $.ajax({
                            "url": "member?opr=del",
                            "dataType": 'text',
                            "type": 'post',
                            "data": {id: obj.data.id},
                            async: false,
                            "success": function (date) {
                                if (date == "true") {
                                    layer.msg('删除成功', {icon: 1, time: 1500}, function () {
                                        tableIns.reload({
                                            where: {},
                                            page: {
                                                curr: 1
                                            }
                                        });
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="用户操作";
                                        let gn="用户删除";
                                        let jg="成功";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                    });
                                } else {
                                    layer.msg('删除失败', {icon: 2, time: 1500});
                                    let b=sessionStorage.obs;
                                    let a=b.replace(/\"/g, "");
                                    let cz="用户操作";
                                    let gn="用户删除";
                                    let jg="失败";
                                    $.ajax({
                                        "url": "gly?opr=xmr",
                                        "data": {name:a,cz:cz,gn:gn,jg:jg}
                                    })
                                }
                            }
                        });
                        layer.close(index);
                    });
                    break;
                case 'edit':
                    if (obj.data.zhuangtai == 0) {
                        layer.msg('您的账号处于封禁状态 无法修改', {icon: 1, time: 1500}, function () {
                        });
                    } else {
                        layer.open({
                            title: '编辑用户',
                            type: 1,
                            shade: 0.2,
                            maxmin: true,
                            shadeClose: true,
                            area: ['100%', '100%'],
                            content: $("#editForm"),
                            success: function () {
                                $("#id").val(obj.data.id);
                                $("#yhm").val(obj.data.name);
                                $("#yx").val(obj.data.email);
                                $("#sjh").val(obj.data.phone);
                                $("#cs").val(obj.data.address);
                                $("#zhuangtai").val(obj.data.zhuangtai);
                                document.getElementById("demo1").src = obj.data.photo;
                                let url = obj.data.photo;
                                var index = url.lastIndexOf("\/");
                                strs = url.substring(index + 1, url.length);
                                $("#photo").val(strs);
                                if (data.sex == "男") {
                                    $("input[name=sex][value='男']").prop("checked", "true");
                                } else {
                                    $("input[name=sex][value='女']").prop("checked", "true");
                                }
                                form.render();
                            },
                        });
                    }
                    break;
                case 'jin':
                    layer.confirm('确定要做此操作吗', function (index) {
                        $.ajax({
                            "url": "member?opr=ztxg",
                            "dataType": 'text',
                            "type": 'post',
                            "data": {id: obj.data.id, zhi: obj.data.zhuangtai},
                            async: false,
                            "success": function (date) {
                                if (date == "true") {
                                    layer.msg('修改成功', {icon: 1, time: 1500}, function () {
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="用户操作";
                                        let gn="用户状态修改";
                                        let jg="成功";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                        tableIns.reload({
                                            where: {},
                                            page: {
                                                curr: 1
                                            }
                                        });
                                    });
                                } else {
                                    layer.msg('修改失败', {icon: 2, time: 1500});
                                    let b=sessionStorage.obs;
                                    let a=b.replace(/\"/g, "");
                                    let cz="用户操作";
                                    let gn="用户状态修改";
                                    let jg="失败";
                                    $.ajax({
                                        "url": "gly?opr=xmr",
                                        "data": {name:a,cz:cz,gn:gn,jg:jg}
                                    })
                                }
                            }
                        });
                        layer.close(index);
                    });
                    break;
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let post_data = $("form").serialize();
            $.ajax({
                "url": "member?opr=addSave2",
                "dataType": 'text',
                "type": 'post',
                "data": post_data,
                async: false,
                "success": function (date) {
                    if (date == "true") {
                        let b=sessionStorage.obs;
                        let a=b.replace(/\"/g, "");
                        let cz="用户操作";
                        let gn="用户修改";
                        let jg="成功";
                        $.ajax({
                            "url": "gly?opr=xmr",
                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                        })
                        // 关闭弹出层
                        layer.closeAll();
                        tableIns.reload({
                            page: {
                                curr: 1
                            }
                        });
                        layer.msg('修改成功', {icon: 1, time: 1500});
                    } else {
                        layer.msg('修改失败', {icon: 2, time: 1500});
                        let b=sessionStorage.obs;
                        let a=b.replace(/\"/g, "");
                        let cz="用户操作";
                        let gn="用户修改";
                        let jg="失败";
                        $.ajax({
                            "url": "gly?opr=xmr",
                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                        })
                    }
                }
            });
            return false;
        });
    })
    function showimg(t) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: '516px',
            skin: 'layui-layer-nobg', //没有背景色
            shadeClose: true,
            content: '<img style="display: inline-block; width: 100%; height: 100%;" src="' + t.src + '">'
        });
    }
</script>
<form id="editForm" method="post" style="display:none;">
    <div class="layui-form layuimini-form">
        <input type="hidden" name="id" id="id">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="name" required lay-verify="required" placeholder="请输入标题" autocomplete="off"
                       class="layui-input" id="yhm"><span class="tishi"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email" lay-verify="required" lay-reqtext="邮箱不能为空" placeholder="请输入邮箱" value=""
                       class="layui-input" id="yx"><span class="tishi2"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机号" value=""
                       class="layui-input" id="sjh"><span class="tishi3"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="男" title="男" checked="">
                <input type="radio" name="sex" value="女" title="女">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">城市</label>
            <div class="layui-input-block">
                <input type="text" name="address" lay-verify="required" lay-reqtext="地址不能为空" placeholder="请输入城市"
                       value="" class="layui-input" id="cs">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="test1">上传图片</button>
                <div class="layui-upload-list">
                    <img onclick="showimg(this)" class="layui-upload-img" id="demo1">
                    <p id="demoText"></p>
                </div>
                <div style="width: 95px;">
                    <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo">
                        <div class="layui-progress-bar" lay-percent=""></div>
                    </div>
                </div>
                <input type="hidden" name="zhuangtai" id="zhuangtai">
            </div>
        </div>
        <%--    隱藏表单 存储上传成功后 回调返回的文件名--%>
        <input type="hidden" name="photo" id="photo"><br>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn" id="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</form>
</body>

</html>